package com.shenglue.ssi.tag;

import java.io.IOException;
import java.util.HashSet;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;


/**
 * @author JiangFeng
 *
 */
public class TreeNodeTag extends TagSupport {

	private static final long serialVersionUID = 1L;

	private String id;	  // id号，可置于数据库中
	private String title; // 显示的文本
	private String url;

	private HashSet allowedIds = new HashSet();

	public int doEndTag () throws JspException {

		allowedIds.add( "buyInId" ); // 先模拟。 准备好后，从 request 取
		// 无  buyBackId

		StringBuffer sb = new StringBuffer();
		sb.append( "<div dojoType=\"struts:StrutsTreeNode\"  id=\"" );
		sb.append( id );
		sb.append( "\"  title=\"" );

		if ( allowedIds.contains( id ) ) {
			// </a>
			sb.append( "<a href='" );
			sb.append( url );
			sb.append( "' title='" );
			sb.append( title );
			sb.append( "'>" );
			sb.append( title );
			sb.append( "</a>" );
		}
		else {
			sb.append( "<font color=#c0c0c0>" );
			sb.append( title );
			sb.append( "</font>" );
		}

		sb.append( "\"></div>" );

		try {
			pageContext.getOut().print( sb );
		} catch ( IOException e ) {
			throw new JspTagException( e.getMessage() );
		}

		return SKIP_BODY;
	}

	public void release() {
		super.release();
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}
